<?php

include_once($cfgPaths['lib'].'cms/type/cmsEditType.o.inc.php');

class cmsEditForeignkeyType extends cmsEditType {

 function registerFields () {
   $map[] = $this->name.'foreignkey';
   $this->map = &$map;
 }

 function render_html () {
   $ds = & dba_DataSource::getInstance();
   $udba = & $ds->getConnection();
   $type = $GLOBALS['env']->getParam('type');
   $is_content_object = $GLOBALS['cfgQueries'][$type]['conf'][$this->name]['iscontentobject'];
   $show_query = ((isset($GLOBALS['cfgQueries'][$type]['conf'][$this->name]['showquery']) && $GLOBALS['cfgQueries'][$type]['conf'][$this->name]['showquery'])?true:false);
   $udba->query("select ".$GLOBALS['cfgQueries'][$type]['conf'][$this->name]['id'].
    " As id, ".$GLOBALS['cfgQueries'][$type]['conf'][$this->name]['value'].
    " As value from ".$GLOBALS['cfgQueries'][$type]['conf'][$this->name]['table'].($is_content_object?" where current='Y'":''), $show_query);
 	  $rows = $udba->fetch_rows_array();
  $html  = '<div class="xicstypeplugin">'."\n";
  $html .= '    <h3>'.$this->descr.':</h3>'.$this->showFields()."\n";
  $html .= '          <select name="'.$this->name.'foreignkey" tabindex="'.$this->sender->getNextTabindex($this->name.'text').'">'."\n";
  $value = $this->getValue($this->name.'foreignkey');
  if (is_array($rows))
  foreach ($rows As $row)
  {
    $html .= '<option';
    if ($value == $row['id'])
        $html .= ' selected="selected"';
    $html .= ' value="'.$row['id'].'">'.$row['value'].'</option>'."\n";
  }
  $html .= '          </select>';
  $html  .= '</div><!-- / type foreignkey -->'."\n";
  return $html;
 }

 function render_javascript () {
 }

}


?>
